import { Toast } from 'antd-mobile'
import { makeAutoObservable } from 'mobx'
import { history } from 'umi'
import { updateUserInfo } from '../api'
import type { UpdateUserInfoParamsType } from '../api/interface'
import { stores } from '@/stores'
// import * as Storage from '@/storage'
import type { UserInfoType } from '@/pages/login/api/interface'
class Store {
    constructor() {
        makeAutoObservable(this)
    }
    async updateData(params: UpdateUserInfoParamsType) {
        await updateUserInfo(params)
        Toast.show('更新成功')
        const newUserInfo = {
            ...stores.userStore.getUserInfo,
            ...params,
        }
        stores.userStore.updateUserInfo(newUserInfo as UserInfoType)
        history.goBack()
    }
}

export default Store
